package com.caojm.mptools.client.commands;

import com.caojm.mptools.client.MiningData;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text;

import java.util.Map;

public class MiningLeaderboardCommand {

    // 注册命令
    public static void register() {
        CommandManager.literal("mp")
                .then(CommandManager.literal("leaderboard")  // 查询榜单命令
                        .executes(context -> {
                            ServerCommandSource source = context.getSource();

                            // 获取前10的挖掘数据
                            Map<String, Integer> top10 = MiningData.getTop10();

                            // 显示榜单
                            StringBuilder leaderboard = new StringBuilder();
                            leaderboard.append("前10名挖掘榜单:\n");
                            top10.forEach((playerName, miningData) -> {
                                leaderboard.append(playerName).append(": ").append(miningData).append(" 次\n");
                            });

                            // 返回榜单
                            source.sendFeedback(() -> Text.literal(leaderboard.toString()), false);
                            return 1;
                        })
                )
                .build();
    }
}
